home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume14 / sharedmem / part01 next >
Encoding:
Internet Message Format  |  1988-05-17  |  60.1 KB

  1. Subject:  v14i094:  Shared memory emulation for 4.2BSD, Part01/04
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: libes@cme-durer.ARPA (Don Libes)
  7. Posting-number: Volume 14, Issue 94
  8. Archive-name: sharedmem/part01
  9.  
  10. This system emulates a shared memory system for 4.2BSD.  A common
  11. memory server handles requests to access shared variables.  Because
  12. communication uses TCP/IP, processes may be distributed across
  13. machines.
  14.  
  15. The system is all user level code and requires no kernel
  16. modifications.  This implementation provides interfaces for C and
  17. Franz Lisp.  It is known to work on Sun UNIX releases from 1.0 to 3.4.
  18.  
  19. The system is documented by the files in the doc directory.
  20. doc/usenix contains a paper that was presented at the Summer 1985
  21. Usenix Conference.  The system has changed somewhat since then.
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 4)."
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'README' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'README'\"
  33. else
  34. echo shar: Extracting \"'README'\" \(1424 characters\)
  35. sed "s/^X//" >'README' <<'END_OF_FILE'
  36. XThe NBS Common Memory System (CMS)
  37. XSept 25, 1987
  38. X
  39. XThis system emulates a shared memory system for 4.2BSD.  A common
  40. Xmemory server handles requests to access shared variables.  Because
  41. Xcommunication uses TCP/IP, processes may be distributed across
  42. Xmachines.
  43. X
  44. XThe system is all user level code and requires no kernel
  45. Xmodifications.  This implementation provides interfaces for C and
  46. XFranz Lisp.  It is known to work on Sun UNIX releases from 1.0 to
  47. X3.4.
  48. X
  49. XThe system is documented by the files in the doc directory.
  50. Xdoc/usenix contains a paper that was presented at the Summer 1985
  51. XUsenix Conference.  The system has changed somewhat since then.
  52. X
  53. XInstallation instructions
  54. X
  55. XThis package depends upon a tiny communications library called
  56. Xstreamlib which must be installed first.
  57. X
  58. X    cd stream
  59. X    cat README
  60. X
  61. Xand follow the directions in there.
  62. X
  63. XOnce you have installed streamlib, change to the common memory
  64. Xsource directory and run make.
  65. X
  66. X    cd ../src
  67. X    make install
  68. X
  69. XIf you would like to try out some of the examples, type:
  70. X
  71. X    make examples
  72. X
  73. XThe examples are numbered as sets.  I.e. client1 runs with server1.
  74. XThe most interesting is server1y, server1z, client1a and client1b.
  75. XRun these in 4 different windows.  They are documented by their
  76. Xsource and serve as coding examples.
  77. X
  78. XDon Libes
  79. XNational Bureau of Standards
  80. XMetrology Building, Room A-127
  81. XGaithersburg, MD  20899
  82. X(301) 975-3535
  83. X
  84. Xlibes@cme-durer.arpa
  85. Xuunet!cme-durer!libes
  86. X
  87. X
  88. END_OF_FILE
  89. if test 1424 -ne `wc -c <'README'`; then
  90.     echo shar: \"'README'\" unpacked with wrong size!
  91. fi
  92. # end of 'README'
  93. fi
  94. if test -f 'cms.3' -a "${1}" != "-c" ; then 
  95.   echo shar: Will not clobber existing file \"'cms.3'\"
  96. else
  97. echo shar: Extracting \"'cms.3'\" \(449 characters\)
  98. sed "s/^X//" >'cms.3' <<'END_OF_FILE'
  99. X.TH CMS 3NBS "11 January 1988"
  100. X.SH NAME
  101. Xshared memory system emulator
  102. X.SH DESCRIPTION
  103. X.PP
  104. XThis system emulates a shared memory system.  A common memory
  105. Xserver handles requests to access shared variables.  Because
  106. Xcommunication uses TCP/IP, processes may be distributed across
  107. Xmachines.
  108. X.PP
  109. XFor further information read the documents in the doc directory
  110. Xthat comes with the common memory source.  There are several
  111. Xexamples in the source directory.
  112. END_OF_FILE
  113. if test 449 -ne `wc -c <'cms.3'`; then
  114.     echo shar: \"'cms.3'\" unpacked with wrong size!
  115. fi
  116. # end of 'cms.3'
  117. fi
  118. if test ! -d 'doc' ; then
  119.     echo shar: Creating directory \"'doc'\"
  120.     mkdir 'doc'
  121. fi
  122. if test ! -d 'doc/usenix' ; then
  123.     echo shar: Creating directory \"'doc/usenix'\"
  124.     mkdir 'doc/usenix'
  125. fi
  126. if test ! -d 'src' ; then
  127.     echo shar: Creating directory \"'src'\"
  128.     mkdir 'src'
  129. fi
  130. if test -f 'src/README' -a "${1}" != "-c" ; then 
  131.   echo shar: Will not clobber existing file \"'src/README'\"
  132. else
  133. echo shar: Extracting \"'src/README'\" \(247 characters\)
  134. sed "s/^X//" >'src/README' <<'END_OF_FILE'
  135. XAm in the process of implementing a way to get the names of the open cm
  136. Xvariables from the cmm.  Idea is to reserve a variable, say, cm_variable_names
  137. Xwhich is written by the cmm whenever a new variable is declared (or the last
  138. Xlink is deleted).
  139. X
  140. END_OF_FILE
  141. if test 247 -ne `wc -c <'src/README'`; then
  142.     echo shar: \"'src/README'\" unpacked with wrong size!
  143. fi
  144. # end of 'src/README'
  145. fi
  146. if test -f 'src/client1a.c' -a "${1}" != "-c" ; then 
  147.   echo shar: Will not clobber existing file \"'src/client1a.c'\"
  148. else
  149. echo shar: Extracting \"'src/client1a.c'\" \(795 characters\)
  150. sed "s/^X//" >'src/client1a.c' <<'END_OF_FILE'
  151. X/* client1a.c
  152. XThis process, a, writes a string to variable a_var.
  153. XIt then checks variable b_var for a new value, and if it is, prints it.
  154. XIt then sleeps for 3 seconds.
  155. X*/
  156. X#include "cm.h"
  157. X
  158. X#define BUFFER_LENGTH    1000
  159. Xchar a_data[BUFFER_LENGTH];
  160. X
  161. Xcm_value a_val = {a_data,BUFFER_LENGTH,0,0}, b_val = {0,0,0,1};
  162. X
  163. Xmain()
  164. X{
  165. X    cm_variable *a_var, *b_var;
  166. X    int seqno = 0;
  167. X
  168. X    if (0> cm_init("a",0,0)) exit(-1);
  169. X
  170. X    if (!(a_var = cm_declare("a_var",CM_ROLE_NONXWRITER)))
  171. X        exit(-1);
  172. X    if (!(b_var = cm_declare("b_var",CM_ROLE_READER|CM_ROLE_WAKEUP)))
  173. X        exit(-1);
  174. X
  175. X    for (;;) {
  176. X        sprintf(a_data,"Message from a.  seq #%d",seqno++);
  177. X        a_val.size = strlen(a_data) + 1;
  178. X        cm_set_value(a_var,&a_val);
  179. X        cm_sync(CM_NO_WAIT);
  180. X        if (cm_get_new_value(b_var,&b_val))
  181. X            printf("b_var: %s\n",b_val.data);
  182. X        sleep(3);
  183. X    }
  184. X}
  185. END_OF_FILE
  186. if test 795 -ne `wc -c <'src/client1a.c'`; then
  187.     echo shar: \"'src/client1a.c'\" unpacked with wrong size!
  188. fi
  189. # end of 'src/client1a.c'
  190. fi
  191. if test -f 'src/client1b.c' -a "${1}" != "-c" ; then 
  192.   echo shar: Will not clobber existing file \"'src/client1b.c'\"
  193. else
  194. echo shar: Extracting \"'src/client1b.c'\" \(807 characters\)
  195. sed "s/^X//" >'src/client1b.c' <<'END_OF_FILE'
  196. X/*
  197. XThis process, b, writes a string to variable b_var.
  198. XIt then checks variable a_var for a new value, and if it is, prints it.
  199. XIt then sleeps for 5 seconds.
  200. X*/
  201. X#include <sys/time.h>
  202. X#include "cm.h"
  203. X
  204. X#define BUFFER_LENGTH    1000
  205. Xchar b_data[BUFFER_LENGTH];
  206. X
  207. Xcm_value a_val = {0,0,0,1}, b_val = {b_data,BUFFER_LENGTH,0,0};
  208. X
  209. Xmain()
  210. X{
  211. X    cm_variable *a_var, *b_var;
  212. X    int seqno = 0;
  213. X
  214. X    if (0> cm_init("b",0,0)) exit(-1);
  215. X
  216. X    if (!(a_var = cm_declare("a_var",CM_ROLE_READER|CM_ROLE_WAKEUP)))
  217. X        exit(-1);
  218. X    if (!(b_var = cm_declare("b_var",CM_ROLE_NONXWRITER)))
  219. X        exit(-1);
  220. X
  221. X    for (;;) {
  222. X        sprintf(b_data,"Message from b.  seq #%d",seqno++);
  223. X        b_val.size = strlen(b_data) + 1;
  224. X        cm_set_value(b_var,&b_val);
  225. X        cm_sync(CM_NO_WAIT);
  226. X        if (cm_get_new_value(a_var,&a_val))
  227. X            printf("a_var: %s\n",a_val.data);
  228. X        sleep(5);
  229. X    }
  230. X}
  231. X
  232. END_OF_FILE
  233. if test 807 -ne `wc -c <'src/client1b.c'`; then
  234.     echo shar: \"'src/client1b.c'\" unpacked with wrong size!
  235. fi
  236. # end of 'src/client1b.c'
  237. fi
  238. if test -f 'src/client2.c' -a "${1}" != "-c" ; then 
  239.   echo shar: Will not clobber existing file \"'src/client2.c'\"
  240. else
  241. echo shar: Extracting \"'src/client2.c'\" \(1056 characters\)
  242. sed "s/^X//" >'src/client2.c' <<'END_OF_FILE'
  243. X/* client2.c
  244. X this client writes the following to common memory:
  245. Xs_var: a line read from stdin
  246. Xi_var: the length of s_var
  247. Xd_var: a random double variable
  248. X*/
  249. X#include <sys/time.h>
  250. X#include "cm.h"
  251. X
  252. Xcm_variable *i_var, *d_var, *s_var;
  253. Xcm_value i_val, d_val, s_val;
  254. Xdouble d_val_data = 3.14159;
  255. X
  256. Xchar s_val_data[1000];
  257. Xint i_val_data;
  258. X
  259. Xmain(argc,argv)
  260. Xint argc;
  261. Xchar **argv;
  262. X{
  263. X    if (argc>1) printf("going to host %s for cmm\n",argv[1]);
  264. X    if (0 > cm_init("don",(argc>1?argv[1]:(char *)0),0)) exit(-1);
  265. X
  266. X    s_var = cm_declare("s_var",CM_ROLE_NONXWRITER);
  267. X    i_var = cm_declare("i_var",CM_ROLE_NONXWRITER);
  268. X    d_var = cm_declare("d_var",CM_ROLE_NONXWRITER);
  269. X
  270. X    d_val.data = (char *)&d_val_data;
  271. X    d_val.size = sizeof(d_val_data);
  272. X    s_val.data = s_val_data;
  273. X    i_val.data = (char *)&i_val_data;
  274. X
  275. X    while (TRUE) {
  276. X        cm_set_value(d_var,&d_val);
  277. X
  278. X        printf("enter string for s_val: ");
  279. X        gets(s_val_data);
  280. X        s_val.size = strlen(s_val_data);
  281. X        cm_set_value(s_var,s_val);
  282. X
  283. X        i_val_data = strlen(s_val_data);
  284. X        cm_set_value(i_var,&i_val);
  285. X
  286. X        if (0 > cm_sync(CM_NO_WAIT)) return;
  287. X    }
  288. X}
  289. END_OF_FILE
  290. if test 1056 -ne `wc -c <'src/client2.c'`; then
  291.     echo shar: \"'src/client2.c'\" unpacked with wrong size!
  292. fi
  293. # end of 'src/client2.c'
  294. fi
  295. if test -f 'src/client8.c' -a "${1}" != "-c" ; then 
  296.   echo shar: Will not clobber existing file \"'src/client8.c'\"
  297. else
  298. echo shar: Extracting \"'src/client8.c'\" \(382 characters\)
  299. sed "s/^X//" >'src/client8.c' <<'END_OF_FILE'
  300. X/* client8.c - constantly write a variable to common memory (see server8.c) */
  301. X
  302. X#include <sys/time.h>
  303. X#include "cm.h"
  304. X
  305. Xcm_variable *variable;
  306. Xcm_value value = { "foo", 4, 4, 0};
  307. X
  308. Xmain()
  309. X{
  310. X    if (0>cm_init("constant writer",0,0)) exit(-1);
  311. X
  312. X    if (!(variable = cm_declare("variable",CM_ROLE_XWRITER))) exit(-1);
  313. X
  314. X    while (1) {
  315. X        cm_set_value(variable,&value);
  316. X        cm_sync(CM_NO_WAIT);
  317. X    }
  318. X}
  319. END_OF_FILE
  320. if test 382 -ne `wc -c <'src/client8.c'`; then
  321.     echo shar: \"'src/client8.c'\" unpacked with wrong size!
  322. fi
  323. # end of 'src/client8.c'
  324. fi
  325. if test -f 'src/cm.h' -a "${1}" != "-c" ; then 
  326.   echo shar: Will not clobber existing file \"'src/cm.h'\"
  327. else
  328. echo shar: Extracting \"'src/cm.h'\" \(269 characters\)
  329. sed "s/^X//" >'src/cm.h' <<'END_OF_FILE'
  330. X/* cm.h - include common memory include files */
  331. X
  332. X#ifndef _TIME_
  333. X#include <sys/time.h>
  334. X#endif
  335. X
  336. X#include "cm_constants.h"
  337. X#include "cm_var.h"
  338. X#include "cm_sd.h"
  339. X#include "cm_interface.h"
  340. X#include "cm_slot.h"
  341. X#include "cm_msg.h"
  342. X#include "cm_sync.h"
  343. X#include "cm_time.h"
  344. END_OF_FILE
  345. if test 269 -ne `wc -c <'src/cm.h'`; then
  346.     echo shar: \"'src/cm.h'\" unpacked with wrong size!
  347. fi
  348. # end of 'src/cm.h'
  349. fi
  350. if test -f 'src/cm.lisp' -a "${1}" != "-c" ; then 
  351.   echo shar: Will not clobber existing file \"'src/cm.lisp'\"
  352. else
  353. echo shar: Extracting \"'src/cm.lisp'\" \(1622 characters\)
  354. sed "s/^X//" >'src/cm.lisp' <<'END_OF_FILE'
  355. X                ; load in calls for common memory package
  356. X                ; Don Libes
  357. X
  358. X(cfasl '/usr/local/lib/Luser.o '_Lcm_init 'cm_init    "function"
  359. X    "/usr/local/lib/libcm.a /usr/local/lib/libstream.a")
  360. X(getaddress
  361. X '_Lcm_declare            'cm_declare        "integer-function"
  362. X '_Lcm_undeclare        'cm_undeclare        "subroutine"
  363. X '_Lcm_sync            'cm_sync        "integer-function"
  364. X '_Lcm_set_value        'cm_set_value        "subroutine"
  365. X '_Lcm_get_value        'cm_get_value        "subroutine"
  366. X '_Lcm_set_new_command_value    'cm_set_new_command_value "integer-function"
  367. X '_Lcm_new_command_pending    'cm_new_command_pending    "integer-function"
  368. X '_Lcm_get_new_command_value    'cm_get_new_command_value "integer-function"
  369. X '_Lcm_status_equal        'cm_status_equal    "integer-function"
  370. X '_Lcm_status_synchronized    'cm_status_synchronized    "integer-function"
  371. X '_Lcm_set_status_value        'cm_set_status_value    "subroutine"
  372. X '_Lcm_print_variable        'cm_print_variable    "subroutine"
  373. X '_Lcm_exit            'cm_exit        "subroutine"
  374. X)
  375. X
  376. X; access types, i.e. roles
  377. X(setq oldibase ibase)
  378. X(setq ibase 8)
  379. X(setq CM_ROLE_NULL            000)
  380. X(setq CM_ROLE_READER            001)
  381. X(setq CM_ROLE_WAKEUP            002)
  382. X(setq CM_ROLE_NONXWRITER        004)
  383. X(setq CM_ROLE_NONEXCLUSIVE_WRITER    004)
  384. X(setq CM_ROLE_EXCLUSIVE_WRITER        014)
  385. X(setq CM_ROLE_XWRITER            014)
  386. X(setq ibase oldibase)
  387. X
  388. X(setq CM_WAIT                0)
  389. X(setq CM_NO_WAIT            1)
  390. X(setq CM_WAIT_FOR_ALL            0)
  391. X(setq CM_WAIT_AT_MOST_ONCE        2)
  392. X(setq CM_WAIT_READ            4)
  393. X
  394. X;(setq CM_WAIT                0)
  395. X;(setq CM_NO_WAIT            1)
  396. X;(setq CM_WAIT_FOR_ALL            2)
  397. X;(setq CM_WAIT_AT_MOST_ONCE        3)
  398. X
  399. X; define common memory value
  400. X(c-declare
  401. X    (struct cm_value
  402. X        (data * char)
  403. X        (msize unsigned-short)
  404. X        (size unsigned-short)
  405. X        (mallocable char)    
  406. X    )
  407. X)
  408. END_OF_FILE
  409. if test 1622 -ne `wc -c <'src/cm.lisp'`; then
  410.     echo shar: \"'src/cm.lisp'\" unpacked with wrong size!
  411. fi
  412. # end of 'src/cm.lisp'
  413. fi
  414. if test -f 'src/cm_bytestuff.h' -a "${1}" != "-c" ; then 
  415.   echo shar: Will not clobber existing file \"'src/cm_bytestuff.h'\"
  416. else
  417. echo shar: Extracting \"'src/cm_bytestuff.h'\" \(372 characters\)
  418. sed "s/^X//" >'src/cm_bytestuff.h' <<'END_OF_FILE'
  419. X/* cm_bytestuff.h - byte stuffing aids */
  420. X
  421. X/* #byteadd is used to add offsets to structures */
  422. X/*#define byteadd(a,b)    (((int)a) + ((int)b) + (((int)a) + (int)b) % 2)*/
  423. X#define byteadd(a,b)    (align(((int)(a)) + ((int)(b))))
  424. X
  425. X/* align converts rounds up addresses if they are odd */
  426. X/* if this is not done, longword stores fail on the 68000 */
  427. X#define align(x)    ((x) + (x)%2)
  428. END_OF_FILE
  429. if test 372 -ne `wc -c <'src/cm_bytestuff.h'`; then
  430.     echo shar: \"'src/cm_bytestuff.h'\" unpacked with wrong size!
  431. fi
  432. # end of 'src/cm_bytestuff.h'
  433. fi
  434. if test -f 'src/cm_constants.h' -a "${1}" != "-c" ; then 
  435.   echo shar: Will not clobber existing file \"'src/cm_constants.h'\"
  436. else
  437. echo shar: Extracting \"'src/cm_constants.h'\" \(445 characters\)
  438. sed "s/^X//" >'src/cm_constants.h' <<'END_OF_FILE'
  439. X#define CM_PORT            1525
  440. X
  441. X/* maximums */
  442. X#define CM_MSGSIZE        100000/* max length of all variables
  443. X                    sent to    server at one time */
  444. X#define CM_SLOTSIZE        20000 /* max single variable length */
  445. X#define CM_PROCESSNAMELENGTH    20
  446. X#define CM_VARIABLENAMELENGTH    20
  447. X#define CM_MAXVARIABLENAMELENGTH    20
  448. X#define CM_MAXPROCESSNAMELENGTH    20
  449. X#define CM_MAXUSERVARIABLES    100
  450. X
  451. X#define E_CMM_DIED        -1
  452. X#define E_CM_INIT_FAILED        -2
  453. X#define E_CM_WRONG_VERSION        -100
  454. END_OF_FILE
  455. if test 445 -ne `wc -c <'src/cm_constants.h'`; then
  456.     echo shar: \"'src/cm_constants.h'\" unpacked with wrong size!
  457. fi
  458. # end of 'src/cm_constants.h'
  459. fi
  460. if test -f 'src/cm_man.h' -a "${1}" != "-c" ; then 
  461.   echo shar: Will not clobber existing file \"'src/cm_man.h'\"
  462. else
  463. echo shar: Extracting \"'src/cm_man.h'\" \(1966 characters\)
  464. sed "s/^X//" >'src/cm_man.h' <<'END_OF_FILE'
  465. X/*
  466. X
  467. XCommon memory is local to the CMM process.  It is composed of:
  468. X
  469. XAn array of variables.  Each variable is a structure with elements such as
  470. Xa name, type, value, etc.
  471. X
  472. XVariable values can be stored in the variable structure if they are small
  473. X(such as an int) or in a piece of malloc'd memory if they are large (such
  474. Xas a string).
  475. X
  476. XAn array of process descriptors.  Each process descriptor is a structure.
  477. XThe most important element of this structure is the wakeup field.  If it is
  478. Xset, the process should be informed of new variable values.
  479. X*/
  480. X
  481. X#define CM_MANAGER_NAME        "cm manager"
  482. X#define CM_MAXVARIABLES        50
  483. X#define CM_MAXPROCESSES        20
  484. X
  485. X#define is_new(proc,var)        (var->role[proc].new)
  486. X#define is_reader(proc,var)        (var->role[proc].reader)
  487. X#define is_wakeup(proc,var)        (var->role[proc].wakeup)
  488. X#define is_writer(proc,var)        (var->role[proc].writer)
  489. X#define is_nonxwriter(proc,var)        (var->role[proc].writer && \
  490. X                     var->xwriter != proc)
  491. X#define is_xwriter(proc,var)        (var->xwriter == proc)
  492. X
  493. X#define CM_NULL_PROCESS        -1
  494. X
  495. X/* process descriptors */
  496. X/* this table is indexed by corresponding file descriptors (or sockets) */
  497. Xstruct process {
  498. X    char name[CM_PROCESSNAMELENGTH];
  499. X    int inuse;
  500. X    int wakeup;            /* per process wakeup */
  501. X};
  502. X
  503. X/* this is how variables are stored internally to the cmm */
  504. Xstruct variable {
  505. X    char name[CM_VARIABLENAMELENGTH];
  506. X    struct cm_value data;    /* data (and size, if necessary) */
  507. X    unsigned long count;    /* nth definition of this var */
  508. X    struct timeval timestamp;    /* when last written */
  509. X    int command_association;
  510. X    int xwriter;            /* name of exclusive writer */
  511. X    int writers;            /* number of (any type of) writers */
  512. X    int readers;            /* number of readers */
  513. X    struct {
  514. X        unsigned reader : 1;    /* reader */
  515. X        unsigned writer : 1;    /* writer */
  516. X        unsigned wakeup : 1;    /* a-wake me */
  517. X        unsigned new    : 1;    /* changed but not read */
  518. X    } role[CM_MAXPROCESSES];
  519. X};
  520. X
  521. X/* internal errors specific to CMM */
  522. X#define E_GET_VARIABLE_NO_SPACE        -1
  523. END_OF_FILE
  524. if test 1966 -ne `wc -c <'src/cm_man.h'`; then
  525.     echo shar: \"'src/cm_man.h'\" unpacked with wrong size!
  526. fi
  527. # end of 'src/cm_man.h'
  528. fi
  529. if test -f 'src/cm_msg.h' -a "${1}" != "-c" ; then 
  530.   echo shar: Will not clobber existing file \"'src/cm_msg.h'\"
  531. else
  532. echo shar: Extracting \"'src/cm_msg.h'\" \(938 characters\)
  533. sed "s/^X//" >'src/cm_msg.h' <<'END_OF_FILE'
  534. X/*
  535. X
  536. XThis file contains definitions relating to message passing between
  537. Xthe CM manager and user.
  538. X
  539. XFollowing is the structure of a message.  Unfortunately, this is illegal
  540. Xbecause "number" is variable as well as the sizeof(slot).  This structure
  541. Xwill be built dynamically when necessary and discarded after the message
  542. Xhas been used (read or written).  In order to make it legal, we will leave
  543. Xcomment out the "slot" field and read/write that by hand.  This hack will
  544. Xbe used throughout the message code.  Yuck.
  545. X
  546. X*/
  547. X
  548. Xstruct msg {
  549. X    int version;        /* version of cmm system */
  550. X    int size;        /* size of msg structure itself */
  551. X    int slots;            /* number of slots */
  552. X    char name[CM_PROCESSNAMELENGTH];
  553. X    char read_wait;        /* TRUE, if sender waiting for an acknowledgement */
  554. X    struct slot data[1];    /* really want [0] */
  555. X} ;
  556. X
  557. X/*
  558. X
  559. XEach message is composed of a header.  The header includes the process name,
  560. Xnumber of slots, and the slots themselves.
  561. X
  562. X*/
  563. X
  564. X
  565. END_OF_FILE
  566. if test 938 -ne `wc -c <'src/cm_msg.h'`; then
  567.     echo shar: \"'src/cm_msg.h'\" unpacked with wrong size!
  568. fi
  569. # end of 'src/cm_msg.h'
  570. fi
  571. if test -f 'src/cm_sd.h' -a "${1}" != "-c" ; then 
  572.   echo shar: Will not clobber existing file \"'src/cm_sd.h'\"
  573. else
  574. echo shar: Extracting \"'src/cm_sd.h'\" \(384 characters\)
  575. sed "s/^X//" >'src/cm_sd.h' <<'END_OF_FILE'
  576. X/* cm_sd.h - sized-data structures */
  577. X
  578. X/* there is no reason why the items typed as shorts cannot be longer */
  579. X
  580. Xtypedef struct cm_value {
  581. X    char *data;
  582. X    unsigned short msize;    /* max size of data */
  583. X    unsigned short size;    /* size of data used */
  584. X    char mallocable;    /* TRUE, if we can free and malloc data */
  585. X} cm_value;
  586. X
  587. Xstruct cm_flattened_data {
  588. X    unsigned short size;
  589. X    char data[1];
  590. X};
  591. END_OF_FILE
  592. if test 384 -ne `wc -c <'src/cm_sd.h'`; then
  593.     echo shar: \"'src/cm_sd.h'\" unpacked with wrong size!
  594. fi
  595. # end of 'src/cm_sd.h'
  596. fi
  597. if test -f 'src/cm_sync.h' -a "${1}" != "-c" ; then 
  598.   echo shar: Will not clobber existing file \"'src/cm_sync.h'\"
  599. else
  600. echo shar: Extracting \"'src/cm_sync.h'\" \(327 characters\)
  601. sed "s/^X//" >'src/cm_sync.h' <<'END_OF_FILE'
  602. X/* cm_sync.h */
  603. X
  604. X/* OR together one from first set to one from second set */
  605. X/* defaults are CM_WAIT|CM_WAIT_FOR_ALL */
  606. X
  607. X/* first set of options */
  608. X#define CM_WAIT            0
  609. X#define CM_NO_WAIT        1
  610. X/* second set of options */
  611. X#define CM_WAIT_FOR_ALL        0
  612. X#define CM_WAIT_AT_MOST_ONCE    2
  613. X/* third set of options */
  614. X#define CM_WAIT_READ        4
  615. END_OF_FILE
  616. if test 327 -ne `wc -c <'src/cm_sync.h'`; then
  617.     echo shar: \"'src/cm_sync.h'\" unpacked with wrong size!
  618. fi
  619. # end of 'src/cm_sync.h'
  620. fi
  621. if test -f 'src/cm_time.c' -a "${1}" != "-c" ; then 
  622.   echo shar: Will not clobber existing file \"'src/cm_time.c'\"
  623. else
  624. echo shar: Extracting \"'src/cm_time.c'\" \(667 characters\)
  625. sed "s/^X//" >'src/cm_time.c' <<'END_OF_FILE'
  626. X/* these are utilities for dealing with timeouts */
  627. X
  628. X#include <stdio.h>
  629. X#include <sys/types.h>
  630. X#include <sys/time.h>
  631. X#include "cm_time.h"
  632. X
  633. Xstruct timeval cm_period_zero, cm_period_infinite;
  634. X
  635. X/* set up some useful constants */
  636. Xcm_time_init()
  637. X{
  638. X    cm_time_zero(&cm_period_zero);
  639. X    cm_period_infinite.tv_sec = (u_long)1000000;
  640. X    cm_period_infinite.tv_usec = (long)0;
  641. X}
  642. X
  643. Xcm_time_zero(p)
  644. Xstruct timeval *p;
  645. X{
  646. X    p->tv_sec = (u_long)0;
  647. X    p->tv_usec = (long)0;
  648. X}
  649. X
  650. Xcm_time_set(p,s,u)
  651. Xstruct timeval *p;
  652. Xint s;
  653. Xint u;
  654. X{
  655. X    p->tv_sec = (u_long)s;
  656. X    p->tv_usec = (long)u;
  657. X}
  658. X
  659. Xcm_time_copy(from,to)
  660. Xstruct timeval *from, *to;
  661. X{
  662. X    safebcopy((char *)from,(char *)to,sizeof(struct timeval));
  663. X}
  664. END_OF_FILE
  665. if test 667 -ne `wc -c <'src/cm_time.c'`; then
  666.     echo shar: \"'src/cm_time.c'\" unpacked with wrong size!
  667. fi
  668. # end of 'src/cm_time.c'
  669. fi
  670. if test -f 'src/cm_time.h' -a "${1}" != "-c" ; then 
  671.   echo shar: Will not clobber existing file \"'src/cm_time.h'\"
  672. else
  673. echo shar: Extracting \"'src/cm_time.h'\" \(116 characters\)
  674. sed "s/^X//" >'src/cm_time.h' <<'END_OF_FILE'
  675. Xextern struct timeval cm_period_zero, cm_period_infinite;
  676. X
  677. X#define time_now(x) gettimeofday(x,(struct timezone *)0)
  678. END_OF_FILE
  679. if test 116 -ne `wc -c <'src/cm_time.h'`; then
  680.     echo shar: \"'src/cm_time.h'\" unpacked with wrong size!
  681. fi
  682. # end of 'src/cm_time.h'
  683. fi
  684. if test -f 'src/cm_util.c' -a "${1}" != "-c" ; then 
  685.   echo shar: Will not clobber existing file \"'src/cm_util.c'\"
  686. else
  687. echo shar: Extracting \"'src/cm_util.c'\" \(2023 characters\)
  688. sed "s/^X//" >'src/cm_util.c' <<'END_OF_FILE'
  689. X/* utilities */
  690. X
  691. X#include <stdio.h>
  692. X#include <strings.h>
  693. X#include <ctype.h>
  694. X#include <varargs.h>
  695. X
  696. X/* uh-oh, looks like Lisp has a bcopy too! */
  697. X/* and it doesn't do the same thing as the C bcopy!  */
  698. X/* Now who wants to know how long this took me to find? */
  699. Xstatic bcopy(s1,s2,length)
  700. Xchar *s1, *s2;
  701. Xint length;
  702. X{
  703. X    while (0 < length--) *s2++ = *s1++;
  704. X}
  705. X
  706. Xvoid
  707. Xsafebcopy(b1,b2,length)
  708. Xchar *b1, *b2;
  709. Xint length;
  710. X{
  711. X    eprintf(9,"safebcopy(%x,%x,%d)\n",b1,b2,length);
  712. X    if (!b1) {
  713. X    printf("error: bcopy dest is null ptr\n");
  714. X    abort();
  715. X    } else if (!b2) {
  716. X    printf("error: bcopy src is null ptr\n");
  717. X    abort();
  718. X    } else bcopy(b1,b2,length);
  719. X}
  720. X
  721. X/* dump first 20 bytes starting at s in hex */
  722. Xhex20(s)
  723. Xchar *s;
  724. X{
  725. X    int i;
  726. X    for (i=0;i<20;i++) printf("%2x",0xff & s[i]);
  727. X    putchar('\n');
  728. X}
  729. X
  730. X/* dump length bytes worth of s in ascii */
  731. Xascii_dump(s,length)
  732. Xchar *s;
  733. Xint length;
  734. X{
  735. X    int i;
  736. X    for (i=0;i<length;i++) {
  737. X        if (isascii(s[i]) && isprint(s[i])) {
  738. X            printf(" %c",s[i]);
  739. X        } else {
  740. X            printf(" %02x",0xff & s[i]);
  741. X        }
  742. X    }
  743. X    putchar('/n');
  744. X}
  745. X
  746. Xint cm_debug_level;       /* controls how many debugging statements are
  747. X                /* printed.  0 means none, higher numbers mean
  748. X                /* more. */
  749. X/* levels are:
  750. X0    nothing
  751. X1
  752. X2    msgs send/received
  753. X3    msgs init, aborted
  754. X4
  755. X5    slots composed, decomposed
  756. X6    slots broken out
  757. X7
  758. X8
  759. X9    bcopy, strcpy, malloc
  760. X*/
  761. Xset_cm_debug_level(level)
  762. Xint level;
  763. X{
  764. X    cm_debug_level = level;
  765. X    eprintf(1,"cm debug level is %d\n",cm_debug_level);
  766. X}
  767. X
  768. X
  769. X/* Debugging function, use like printf, but the global var debug_level */
  770. X/* controls how much is printed */
  771. X#if 0
  772. X/* Yes, I know its gross */
  773. X/*VARARGS2*/
  774. Xeprintf(level,fmt,v1,v2,v3,v4,v5,v6,v7,v8,v9)
  775. Xint level;
  776. Xchar *fmt;
  777. Xint v1, v2, v3, v4, v5, v6, v7, v8, v9;
  778. X{
  779. X    if (cm_debug_level >= level) printf(fmt,v1,v2,v3,v4,v5,v6,v7,v8,v9);
  780. X}
  781. X#endif
  782. X
  783. X/*VARARGS2*/
  784. Xeprintf(level,fmt,va_alist)
  785. Xint level;
  786. Xchar *fmt;
  787. Xva_dcl
  788. X{
  789. X    va_list pvar;
  790. X
  791. X    va_start(pvar);
  792. X    /* & may be incorrect in following statement */
  793. X    if (cm_debug_level >= level) _doprnt(fmt,pvar,stderr);
  794. X    va_end(pvar);
  795. X}
  796. END_OF_FILE
  797. if test 2023 -ne `wc -c <'src/cm_util.c'`; then
  798.     echo shar: \"'src/cm_util.c'\" unpacked with wrong size!
  799. fi
  800. # end of 'src/cm_util.c'
  801. fi
  802. if test -f 'src/cm_var.h' -a "${1}" != "-c" ; then 
  803.   echo shar: Will not clobber existing file \"'src/cm_var.h'\"
  804. else
  805. echo shar: Extracting \"'src/cm_var.h'\" \(255 characters\)
  806. sed "s/^X//" >'src/cm_var.h' <<'END_OF_FILE'
  807. X/* access types, i.e. roles */
  808. X#define CM_ROLE_NULL            000
  809. X#define CM_ROLE_READER            001
  810. X#define CM_ROLE_WAKEUP            002
  811. X#define CM_ROLE_NONXWRITER        004
  812. X#define CM_ROLE_NONEXCLUSIVE_WRITER    004
  813. X#define CM_ROLE_EXCLUSIVE_WRITER    010
  814. X#define CM_ROLE_XWRITER            010
  815. END_OF_FILE
  816. if test 255 -ne `wc -c <'src/cm_var.h'`; then
  817.     echo shar: \"'src/cm_var.h'\" unpacked with wrong size!
  818. fi
  819. # end of 'src/cm_var.h'
  820. fi
  821. if test ! -d 'src/franz' ; then
  822.     echo shar: Creating directory \"'src/franz'\"
  823.     mkdir 'src/franz'
  824. fi
  825. if test -f 'src/franz/dfuncs.h' -a "${1}" != "-c" ; then 
  826.   echo shar: Will not clobber existing file \"'src/franz/dfuncs.h'\"
  827. else
  828. echo shar: Extracting \"'src/franz/dfuncs.h'\" \(1350 characters\)
  829. sed "s/^X//" >'src/franz/dfuncs.h' <<'END_OF_FILE'
  830. X/*                    -[Mon Dec  3 16:37:08 1984 by layer]-
  831. X *     dfuncs.h            $Locker:  $
  832. X * external function declaration
  833. X *
  834. X * $Header: dfuncs.h,v 40.6 85/03/12 12:54:37 layer Exp $
  835. X *
  836. X * (c) copyright 1982, Regents of the University of California
  837. X * Enhancements (c) copyright 1984, Franz Inc., Oakland California
  838. X */
  839. Xchar *brk();
  840. Xchar *pinewstr();
  841. Xchar *inewstr();
  842. Xchar *newstr();
  843. Xchar *sbrk();
  844. Xchar *xsbrk();
  845. Xchar *ysbrk();
  846. Xint csizeof();
  847. Xlispval Iget();
  848. Xlispval Imakeht();
  849. Xlispval Imkrtab();
  850. Xlispval Iputprop();
  851. Xlispval Istsrch();
  852. Xlispval Lfuncal();
  853. Xlispval Lnegp();
  854. Xlispval Lread();
  855. Xlispval Lsub();
  856. Xlispval copval();
  857. Xlispval csegment();
  858. Xlispval error();
  859. Xlispval errorh();
  860. Xlispval errorh1();
  861. Xlispval errorh2();
  862. Xlispval eval();
  863. Xlispval gc();
  864. Xlispval getatom();
  865. Xlispval inewatom();
  866. Xlispval inewint();
  867. Xlispval inewval();
  868. Xlispval matom();
  869. Xlispval mfun();
  870. Xlispval mstr();
  871. Xlispval newarray();
  872. Xlispval newdot();
  873. Xlispval newdoub();
  874. Xlispval newfunct();
  875. Xlispval newint();
  876. Xlispval newsdot();
  877. Xlispval newval();
  878. Xlispval newhunk();
  879. Xlispval pnewdot();
  880. Xlispval pnewdb();
  881. Xlispval pnewhunk();
  882. Xlispval pnewint();
  883. Xlispval pnewsdot();
  884. Xlispval pnewval();
  885. Xlispval popnames();
  886. Xlispval r();
  887. Xlispval ratomr();
  888. Xlispval readr();
  889. Xlispval readrx();
  890. Xlispval readry();
  891. Xlispval typefrob();
  892. Xlispval typred();
  893. Xlispval unprot();
  894. Xlispval verify();
  895. Xstruct atom    *makeatom();
  896. Xstruct atom    *newatom();
  897. END_OF_FILE
  898. if test 1350 -ne `wc -c <'src/franz/dfuncs.h'`; then
  899.     echo shar: \"'src/franz/dfuncs.h'\" unpacked with wrong size!
  900. fi
  901. # end of 'src/franz/dfuncs.h'
  902. fi
  903. if test -f 'src/franz/lconf.h' -a "${1}" != "-c" ; then 
  904.   echo shar: Will not clobber existing file \"'src/franz/lconf.h'\"
  905. else
  906. echo shar: Extracting \"'src/franz/lconf.h'\" \(16 characters\)
  907. sed "s/^X//" >'src/franz/lconf.h' <<'END_OF_FILE'
  908. X#define sun_4_2
  909. END_OF_FILE
  910. if test 16 -ne `wc -c <'src/franz/lconf.h'`; then
  911.     echo shar: \"'src/franz/lconf.h'\" unpacked with wrong size!
  912. fi
  913. # end of 'src/franz/lconf.h'
  914. fi
  915. if test -f 'src/franz/ltypes.h' -a "${1}" != "-c" ; then 
  916.   echo shar: Will not clobber existing file \"'src/franz/ltypes.h'\"
  917. else
  918. echo shar: Extracting \"'src/franz/ltypes.h'\" \(1031 characters\)
  919. sed "s/^X//" >'src/franz/ltypes.h' <<'END_OF_FILE'
  920. X/*                    -[Wed May 15 10:14:01 1985 by layer]-
  921. X *     ltypes.h            $Locker:  $
  922. X * lisp data type defs
  923. X *
  924. X * $Header: ltypes.h,v 40.6 85/05/16 03:58:00 smh Exp $
  925. X *
  926. X * (c) copyright 1982, Regents of the University of California
  927. X * Enhancements (c) copyright 1984, Franz Inc., Oakland California
  928. X */
  929. X/* type flags */
  930. X
  931. X#define    UNBO    -1
  932. X#define    STRNG    0
  933. X#define    ATOM    1
  934. X#define    INT    2
  935. X#define    DTPR    3
  936. X#define DOUB    4
  937. X#define    BCD    5
  938. X#define    PORT    6
  939. X#define    ARRAY    7
  940. X#define OTHER   8
  941. X#define SDOT    9
  942. X#define VALUE    10
  943. X
  944. X#define HUNK2    11        /* The hunks */
  945. X#define HUNK4    12
  946. X#define HUNK8    13
  947. X#define HUNK16    14
  948. X#define HUNK32    15
  949. X#define HUNK64    16
  950. X#define HUNK128    17
  951. X
  952. X#define VECTOR  18
  953. X#define VECTORI 19
  954. X
  955. X#define NUMSPACES (VECTORI + 1)
  956. X
  957. X#define    HUNKP(a1)    ((TYPE(a1) >= HUNK2) & (TYPE(a1) <= HUNK128))
  958. X
  959. X#define HASHTP(p)    ((p)->v.vector[VPropOff] == hasht_atom)
  960. X#define PACKAGEP(p)    ((p)->v.vector[VPropOff] == pkg_atom)
  961. X#define INSTANCEP(p)    ((TYPE((p)->v.vector[VPropOff]) == VECTOR) && \
  962. X             ((p)->v.vector[VPropOff]->v.vector[VPROPOFF] == \
  963. X              flavor))
  964. X
  965. END_OF_FILE
  966. if test 1031 -ne `wc -c <'src/franz/ltypes.h'`; then
  967.     echo shar: \"'src/franz/ltypes.h'\" unpacked with wrong size!
  968. fi
  969. # end of 'src/franz/ltypes.h'
  970. fi
  971. if test -f 'src/franz/module.h' -a "${1}" != "-c" ; then 
  972.   echo shar: Will not clobber existing file \"'src/franz/module.h'\"
  973. else
  974. echo shar: Extracting \"'src/franz/module.h'\" \(1662 characters\)
  975. sed "s/^X//" >'src/franz/module.h' <<'END_OF_FILE'
  976. X/*                    -[Sat Jun  2 08:09:36 1984 by jkf]-
  977. X *     module.h            $Locker:  $
  978. X * 
  979. X *  module interface includes
  980. X *
  981. X * $Header: module.h,v 40.2 84/11/13 14:23:46 schlafly Exp $
  982. X *
  983. X * (c) copyright 1984, Franz Inc., Oakland California
  984. X */
  985. X
  986. X/*
  987. X * All C coded modules will contain a VERSION
  988. X * header in which the rcs header is stored
  989. X */
  990. X#ifndef lint
  991. X#define VERSION(s)    static char *rcsid = s
  992. X#else
  993. X#define VERSION(s)
  994. X#endif
  995. X
  996. X
  997. X/*
  998. X * All variables are either private in the module or else are
  999. X * shared among 2 or more files.
  1000. X * Private variables are declared Private inside the file.
  1001. X * Non-private variables are either declared Public in a .h file which
  1002. X * all files that wish to reference that variable must include,
  1003. X * or are declared Export in a C (non-header) file.  C files wishing
  1004. X * to reference those variables declare the variable Import.
  1005. X * 
  1006. X *
  1007. X * Private corresponds to 'static' in C, although it usually isn't a good
  1008. X * idea to declare variables or functions to be static if you want to debug
  1009. X * the code with something like adb.
  1010. X * Export corresponds to '' (nothing), and Import to 'extern'.
  1011. X * Public corresponds to 'extern' in C, although there must be one file
  1012. X * in which the 'extern' isn't declared.  To order to strip the extern,
  1013. X * the macro DefineData should be set before including files.
  1014. X *
  1015. X * Public should be used instead of Import and Export since it assures
  1016. X * that every module gets the same declaration.  However it does require
  1017. X * a .h file, and this may be too much effort for one or two variables.
  1018. X *
  1019. X */
  1020. X#define Private static
  1021. X#define Export
  1022. X#define Import extern
  1023. X
  1024. X#ifdef DefineData
  1025. X# define Public
  1026. X#else
  1027. X# define Public extern
  1028. X#endif
  1029. END_OF_FILE
  1030. if test 1662 -ne `wc -c <'src/franz/module.h'`; then
  1031.     echo shar: \"'src/franz/module.h'\" unpacked with wrong size!
  1032. fi
  1033. # end of 'src/franz/module.h'
  1034. fi
  1035. if test -f 'src/franz/public.h' -a "${1}" != "-c" ; then 
  1036.   echo shar: Will not clobber existing file \"'src/franz/public.h'\"
  1037. else
  1038. echo shar: Extracting \"'src/franz/public.h'\" \(1909 characters\)
  1039. sed "s/^X//" >'src/franz/public.h' <<'END_OF_FILE'
  1040. X/*                    -[Tue May 21 17:05:40 1985 by layer]-
  1041. X *     public.h            $Locker:  $
  1042. X *
  1043. X *   definition for Public data objects which all files are permitted
  1044. X *   to look at. [These are the very public data objects]
  1045. X *
  1046. X * $Header: public.h,v 40.5 85/05/21 17:24:04 layer Exp $
  1047. X *
  1048. X * 
  1049. X * (c) copyright 1984, Franz Inc., Oakland California
  1050. X */
  1051. X
  1052. X#ifdef apollo
  1053. Xextern
  1054. X#else
  1055. XPublic
  1056. X#endif
  1057. Xstruct nament *bnp;    /* first free bindstack entry */
  1058. XPublic struct nament *bnplim,    /* limit of bindstack */
  1059. X             *orgbnp;    /* base of the bindstack */
  1060. X
  1061. X
  1062. X#ifdef NPINREG
  1063. XImport
  1064. X#else
  1065. X#ifdef apollo
  1066. Xextern
  1067. X#else
  1068. XPublic
  1069. X#endif apollo
  1070. X#endif NPINREG
  1071. X    struct     argent *lbot,    /* base of arguments to function */
  1072. X                 *np;    /* first free namestack entry */
  1073. X             
  1074. XPublic struct argent *nplim,    /* one above limit of namestack */
  1075. X             *orgnp;    /* first slot in the namestack */
  1076. X             
  1077. X#ifdef apollo
  1078. Xextern
  1079. X#else
  1080. XPublic
  1081. X#endif apollo
  1082. X    word retval;        /* used by each error/prog call     */
  1083. X                /* retval could be an int */
  1084. X#ifdef apollo
  1085. Xextern
  1086. X#else
  1087. XPublic
  1088. X#endif apollo
  1089. Xlispval  lispretval;    /* used by non-local go  */
  1090. X
  1091. XPublic lispval datalim;        /* limit of valid data area */
  1092. X
  1093. XPublic lispval vtemp;        /* used in a few macros as a temp */
  1094. XPublic long sigintcnt;        /* count of interrupts since processed */
  1095. X                /* sigintcnt could be an int */
  1096. X
  1097. XImport char typetable[];        /* one byte per page */
  1098. X
  1099. X#ifdef MVR
  1100. X/* Stuff having to do with Multiple Values */
  1101. X#ifdef apollo
  1102. Xextern
  1103. X#else
  1104. XPublic
  1105. X#endif apollo
  1106. Xint nmvr;        /* # of multiple values being returned less 1 */
  1107. XImport int mmvr;        /* Max # of multiple values possibly returned*/
  1108. X#ifdef apollo
  1109. Xextern
  1110. X#else
  1111. XPublic
  1112. X#endif apollo
  1113. Xlispval *mvals;        /* pointer to a static storage area for them */
  1114. XPublic lispval *mvalsMMVR;  /* pointer to end of storage area for them */
  1115. X#define clrnmv() (nmvr = 0);
  1116. X#endif MVR
  1117. X
  1118. X#ifdef Savelisp
  1119. XPublic lispval relvectors;  /* for save/restorelisp */
  1120. X#endif Savelisp
  1121. END_OF_FILE
  1122. if test 1909 -ne `wc -c <'src/franz/public.h'`; then
  1123.     echo shar: \"'src/franz/public.h'\" unpacked with wrong size!
  1124. fi
  1125. # end of 'src/franz/public.h'
  1126. fi
  1127. if test -f 'src/man_put_slot.c' -a "${1}" != "-c" ; then 
  1128.   echo shar: Will not clobber existing file \"'src/man_put_slot.c'\"
  1129. else
  1130. echo shar: Extracting \"'src/man_put_slot.c'\" \(1541 characters\)
  1131. sed "s/^X//" >'src/man_put_slot.c' <<'END_OF_FILE'
  1132. X/*
  1133. X
  1134. XThese routines build slots for the cmm.  These slots are placed into a
  1135. Xmsg structure and sent to the user.
  1136. X
  1137. X*/
  1138. X
  1139. X#include <stdio.h>
  1140. X#include <sys/time.h>
  1141. X#include "cm_constants.h"
  1142. X#include "cm_sd.h"
  1143. X#include "cm_slot.h"    /* definitions of slot structures */
  1144. X#include "cm_bytestuff.h"
  1145. X
  1146. Xextern struct msg *omsg;    /* this is soooo... messy */
  1147. X
  1148. Xput_slot_read_response(m,name,count,timestamp,cmd,data)
  1149. Xstruct msg *m;
  1150. Xchar *name;
  1151. Xunsigned long count;
  1152. Xstruct timeval *timestamp;
  1153. Xint cmd;
  1154. Xcm_value *data;
  1155. X{
  1156. X    struct big_slot s;
  1157. X    unsigned int size;
  1158. X
  1159. X    init_slot(&s,name,CM_SLOT_READ_RESPONSE);
  1160. X    size = align(sizeof(struct slot_hdr));
  1161. X    size += align(sizeof(struct slot_read_response_hdr));
  1162. X    s.subslot.read_response.srr_count = count;
  1163. X    cm_time_copy(timestamp,&s.subslot.read_response.srr_timestamp);
  1164. X    s.subslot.read_response.srr_command_association = cmd;
  1165. X    size += cm_sd_to_flat(data,&s.subslot.read_response.fdata);
  1166. X    finish_slot(m,&s,size);
  1167. X}
  1168. X
  1169. X/* error slots should never be generated by the user since infinite loops */
  1170. X/* could result between the user and cmm sending each other back error slots */
  1171. Xput_slot_error(m,name,type,string)
  1172. Xstruct msg *m;
  1173. Xchar *name;
  1174. Xint type;
  1175. Xchar *string;
  1176. X{
  1177. X    struct big_slot s;
  1178. X    unsigned int size;
  1179. X
  1180. X    fprintf(stdout,"slot error in <%s>  type %d - %s\n",name,type,string);
  1181. X    
  1182. X    init_slot(&s,name,CM_SLOT_ERROR);
  1183. X    size = align(sizeof(struct slot_hdr));
  1184. X    size += align(sizeof(struct slot_error_hdr));
  1185. X    size += strlen(string) + 1;
  1186. X    s.subslot.error.se_type = type;
  1187. X    strcpy(s.subslot.error.msg,string);
  1188. X    finish_slot(m,&s,size);
  1189. X}
  1190. END_OF_FILE
  1191. if test 1541 -ne `wc -c <'src/man_put_slot.c'`; then
  1192.     echo shar: \"'src/man_put_slot.c'\" unpacked with wrong size!
  1193. fi
  1194. # end of 'src/man_put_slot.c'
  1195. fi
  1196. if test -f 'src/msg.c' -a "${1}" != "-c" ; then 
  1197.   echo shar: Will not clobber existing file \"'src/msg.c'\"
  1198. else
  1199. echo shar: Extracting \"'src/msg.c'\" \(966 characters\)
  1200. sed "s/^X//" >'src/msg.c' <<'END_OF_FILE'
  1201. X/* msg.c */
  1202. X
  1203. X#include <sys/time.h>
  1204. X#include "cm_constants.h"
  1205. X#include "cm_sd.h"
  1206. X#include "cm_slot.h"
  1207. X#include "cm_msg.h"
  1208. X#include "cm_bytestuff.h"
  1209. X
  1210. Xextern int cm_debug_level;
  1211. X
  1212. X/* returns NULL if no more slots */
  1213. Xstruct slot *
  1214. Xnextslot(m,s)
  1215. Xstruct msg *m;
  1216. Xstruct slot *s;
  1217. X{
  1218. X    struct slot *next;
  1219. X
  1220. X    next = (struct slot *)byteadd(s,s->s_size);
  1221. X    if (next >= (struct slot *)byteadd(m,m->size))
  1222. X        return((struct slot *)0);
  1223. X    return(next);
  1224. X}
  1225. X
  1226. Xprint_msg(m)
  1227. Xstruct msg *m;
  1228. X{
  1229. X    struct slot *s;
  1230. X
  1231. X    eprintf(3,"msg header:");
  1232. X    eprintf(3," size = %d",m->size);
  1233. X    eprintf(3," slots = %d",m->slots);
  1234. X    eprintf(3," name = %s",m->name);
  1235. X    eprintf(3," read_wait = %d\n",m->read_wait);
  1236. X    for (s=m->data;s;s=nextslot(m,s)) {
  1237. X        eprintf(5,"slot: name = %s",s->s_name);
  1238. X        eprintf(5," &slot = %x",s);
  1239. X        eprintf(5," size = %d\n",s->s_size);
  1240. X        if (s->s_size == 0) {
  1241. X            eprintf(5,"0 length slot encountered in print_msg\n");
  1242. X            break;
  1243. X        }
  1244. X    }
  1245. X    if (cm_debug_level >= 10) ascii_dump((char *)m,m->size);
  1246. X}
  1247. X
  1248. END_OF_FILE
  1249. if test 966 -ne `wc -c <'src/msg.c'`; then
  1250.     echo shar: \"'src/msg.c'\" unpacked with wrong size!
  1251. fi
  1252. # end of 'src/msg.c'
  1253. fi
  1254. if test -f 'src/name.c' -a "${1}" != "-c" ; then 
  1255.   echo shar: Will not clobber existing file \"'src/name.c'\"
  1256. else
  1257. echo shar: Extracting \"'src/name.c'\" \(216 characters\)
  1258. sed "s/^X//" >'src/name.c' <<'END_OF_FILE'
  1259. X/* set_cm_process_name.c */
  1260. X
  1261. X#include <stdio.h>
  1262. X#include "cm_constants.h"
  1263. X
  1264. Xchar cm_process_name[CM_PROCESSNAMELENGTH];
  1265. X
  1266. Xset_cm_process_name(name)
  1267. Xchar *name;
  1268. X{
  1269. X    strncpy(cm_process_name,name,CM_PROCESSNAMELENGTH);
  1270. X}
  1271. X
  1272. END_OF_FILE
  1273. if test 216 -ne `wc -c <'src/name.c'`; then
  1274.     echo shar: \"'src/name.c'\" unpacked with wrong size!
  1275. fi
  1276. # end of 'src/name.c'
  1277. fi
  1278. if test -f 'src/put_slot.c' -a "${1}" != "-c" ; then 
  1279.   echo shar: Will not clobber existing file \"'src/put_slot.c'\"
  1280. else
  1281. echo shar: Extracting \"'src/put_slot.c'\" \(2010 characters\)
  1282. sed "s/^X//" >'src/put_slot.c' <<'END_OF_FILE'
  1283. X/*
  1284. X
  1285. XThese are some utility routines for building slots.  These slots
  1286. Xare placed in a msg structure and sent from the user to the cmm or vice-versa.
  1287. X
  1288. X*/
  1289. X
  1290. X#include <stdio.h>
  1291. X#include <sys/time.h>
  1292. X#include <strings.h>
  1293. X#include "cm_constants.h"
  1294. X#include "cm_sd.h"
  1295. X#include "cm_slot.h"    /* definitions of slot structures */
  1296. X#include "cm_msg.h"    /* definitions of msg structures */
  1297. X#include "cm_bytestuff.h"
  1298. X
  1299. X#define TRUE 1
  1300. X#define FALSE 0
  1301. X
  1302. Xextern char cm_process_name[];
  1303. X
  1304. Xint    /* returns # of bytes written into msg structure */
  1305. Xfinish_slot(m,slot,slotsize)
  1306. Xstruct msg *m;
  1307. Xstruct slot *slot;
  1308. Xunsigned int slotsize;
  1309. X{
  1310. X    if (m->size + slotsize > CM_MSGSIZE) {
  1311. X        fprintf(stderr,"too much data for msg!!\n");
  1312. X        fprintf(stderr,"output msg size = %d  slotsize = %d  CM_MSGSIZE = %d\n",
  1313. X            m->size,slotsize,CM_MSGSIZE);
  1314. X        return(0);
  1315. X    }
  1316. X    /* copy slot into msg after previous slot */
  1317. X    slot->s_size = slotsize; /* this is not aligned, right? */
  1318. X    eprintf(10,"finish_slot: bcopying slot (size = %d) into msg\n",
  1319. X                        slot->s_size);
  1320. X    safebcopy((char *)slot,(char *)byteadd(m,m->size),slotsize);
  1321. X    eprintf(10,"finish_slot: after bcopy, message slot size = %d\n",
  1322. X                ((struct slot *)byteadd(m,m->size))->s_size);
  1323. X    m->slots++;
  1324. X    m->size += align(slotsize);
  1325. X    return(align(slotsize));
  1326. X}
  1327. X
  1328. Xinit_msg(m)
  1329. Xstruct msg *m;
  1330. X{
  1331. X    m->version = CMM_VERSION;
  1332. X    m->slots = 0;
  1333. X    m->read_wait = FALSE;
  1334. X    strcpy(m->name,cm_process_name);
  1335. X    m->size = sizeof(struct msg) - sizeof(struct slot);
  1336. X}
  1337. X
  1338. X/*
  1339. Xinit_slot does the following:
  1340. X    sets the slot name and type
  1341. X*/
  1342. Xinit_slot(s,name,type)
  1343. Xstruct slot *s;
  1344. Xchar *name;
  1345. Xint type;
  1346. X{
  1347. X    s->s_type = type;
  1348. X    strcpy(s->s_name,name);
  1349. X}
  1350. X
  1351. Xchar *
  1352. Xcm_slot_type(t)
  1353. Xint t;
  1354. X{
  1355. X    switch (t) {
  1356. X    case CM_SLOT_NULL: return("null slot type");
  1357. X    case CM_SLOT_DECLARE: return("declare");
  1358. X    case CM_SLOT_WRITE: return("write");
  1359. X    case CM_SLOT_READ: return("read");
  1360. X    case CM_SLOT_READ_RESPONSE: return("read response");
  1361. X    case CM_SLOT_ERROR: return("error");
  1362. X    case CM_SLOT_UNDECLARE: return("undeclare");
  1363. X    default: return("unknown slot type");
  1364. X    }
  1365. X}
  1366. END_OF_FILE
  1367. if test 2010 -ne `wc -c <'src/put_slot.c'`; then
  1368.     echo shar: \"'src/put_slot.c'\" unpacked with wrong size!
  1369. fi
  1370. # end of 'src/put_slot.c'
  1371. fi
  1372. if test -f 'src/server1y.c' -a "${1}" != "-c" ; then 
  1373.   echo shar: Will not clobber existing file \"'src/server1y.c'\"
  1374. else
  1375. echo shar: Extracting \"'src/server1y.c'\" \(652 characters\)
  1376. sed "s/^X//" >'src/server1y.c' <<'END_OF_FILE'
  1377. X/* server1y.c
  1378. X
  1379. XThis process prints the latest values of variables a_var and b_var when
  1380. Xthe user presses return.
  1381. X
  1382. X*/
  1383. X#include <sys/time.h>
  1384. X#include "cm.h"
  1385. X
  1386. Xcm_value a_val = {0,0,0,1}, b_val = {0,0,0,1};
  1387. X
  1388. Xmain()
  1389. X{
  1390. X    cm_variable *a_var, *b_var;
  1391. X
  1392. X    if (0>cm_init("press return",0,0)) exit(-1);
  1393. X
  1394. X    if (!(a_var = cm_declare("a_var",CM_ROLE_READER)))
  1395. X            exit(-1);
  1396. X    if (!(b_var = cm_declare("b_var",CM_ROLE_READER)))
  1397. X            exit(-1);
  1398. X
  1399. X    printf("press return for latest values\n");
  1400. X    for (;;) {
  1401. X        getchar();
  1402. X        cm_sync(CM_WAIT_READ);
  1403. X        cm_get_value(a_var,&a_val);
  1404. X        printf("a_var: %s\n",a_val.data);
  1405. X        cm_get_value(b_var,&b_val);
  1406. X        printf("b_var: %s\n",b_val.data);
  1407. X    }
  1408. X}
  1409. END_OF_FILE
  1410. if test 652 -ne `wc -c <'src/server1y.c'`; then
  1411.     echo shar: \"'src/server1y.c'\" unpacked with wrong size!
  1412. fi
  1413. # end of 'src/server1y.c'
  1414. fi
  1415. if test -f 'src/server1z.c' -a "${1}" != "-c" ; then 
  1416.   echo shar: Will not clobber existing file \"'src/server1z.c'\"
  1417. else
  1418. echo shar: Extracting \"'src/server1z.c'\" \(610 characters\)
  1419. sed "s/^X//" >'src/server1z.c' <<'END_OF_FILE'
  1420. X/* server1.c
  1421. XThis process, s, prints the latest values of variables a_var and b_var
  1422. X*/
  1423. X#include <sys/time.h>
  1424. X#include "cm.h"
  1425. X
  1426. Xcm_value a_val = {0,0,0,1}, b_val = {0,0,0,1};
  1427. X
  1428. Xmain()
  1429. X{
  1430. X    cm_variable *a_var, *b_var;
  1431. X
  1432. X    if (0>cm_init("s",0,0)) exit(-1);
  1433. X
  1434. X    if (!(a_var = cm_declare("a_var",CM_ROLE_READER|CM_ROLE_WAKEUP)))
  1435. X            exit(-1);
  1436. X    if (!(b_var = cm_declare("b_var",CM_ROLE_READER|CM_ROLE_WAKEUP)))
  1437. X            exit(-1);
  1438. X
  1439. X    for (;;) {
  1440. X        cm_sync(CM_WAIT_AT_MOST_ONCE);
  1441. X        if (cm_get_new_value(a_var,&a_val))
  1442. X            printf("a_var: %s\n",a_val.data);
  1443. X        if (cm_get_new_value(b_var,&b_val))
  1444. X            printf("b_var: %s\n",b_val.data);
  1445. X    }
  1446. X}
  1447. END_OF_FILE
  1448. if test 610 -ne `wc -c <'src/server1z.c'`; then
  1449.     echo shar: \"'src/server1z.c'\" unpacked with wrong size!
  1450. fi
  1451. # end of 'src/server1z.c'
  1452. fi
  1453. if test -f 'src/server2.c' -a "${1}" != "-c" ; then 
  1454.   echo shar: Will not clobber existing file \"'src/server2.c'\"
  1455. else
  1456. echo shar: Extracting \"'src/server2.c'\" \(823 characters\)
  1457. sed "s/^X//" >'src/server2.c' <<'END_OF_FILE'
  1458. X/* all this server does is print out whatever its given */
  1459. X
  1460. X/* Note, this has not been converted over to use cmm v7!!! */
  1461. X
  1462. X#include <sys/time.h>
  1463. X#include "cm.h"
  1464. X
  1465. Xmain(argc,argv)
  1466. Xint argc;
  1467. Xchar **argv;
  1468. X{
  1469. X    cm_variable *i_var, *d_var, *s_var;
  1470. X    char s_val[1000];
  1471. X    int i_val;
  1472. X    double d_val;
  1473. X
  1474. X    if (argc>1) printf("going to host %s for cmm\n",argv[1]);
  1475. X    if (0 > cm_init("printer",(argc>1?argv[1]:(char *)0),0)) exit(-1);
  1476. X
  1477. X    i_var = cm_declare("i_var",CM_ROLE_READER | CM_ROLE_WAKEUP);
  1478. X    d_var = cm_declare("d_var",CM_ROLE_READER);
  1479. X    s_var = cm_declare("s_var",CM_ROLE_READER);
  1480. X
  1481. X    while (TRUE) {
  1482. X        if (0 > cm_sync(CM_WAIT_AT_MOST_ONCE)) return;
  1483. X        cm_get_value(i_var,&i_val);
  1484. X        printf("i_var = %d\n",i_val);
  1485. X        cm_get_value(d_var,&d_val);
  1486. X        printf("d_var = %g\n",d_val);
  1487. X        cm_get_value(s_var,s_val);
  1488. X        printf("s_var = %s\n",s_val);
  1489. X    }
  1490. X}
  1491. END_OF_FILE
  1492. if test 823 -ne `wc -c <'src/server2.c'`; then
  1493.     echo shar: \"'src/server2.c'\" unpacked with wrong size!
  1494. fi
  1495. # end of 'src/server2.c'
  1496. fi
  1497. if test -f 'src/server8a.c' -a "${1}" != "-c" ; then 
  1498.   echo shar: Will not clobber existing file \"'src/server8a.c'\"
  1499. else
  1500. echo shar: Extracting \"'src/server8a.c'\" \(388 characters\)
  1501. sed "s/^X//" >'src/server8a.c' <<'END_OF_FILE'
  1502. X/* server8a.c - constant wait on common memory to test that cmm doesn't */
  1503. X/* blow up when we die and it is writing to us (SIGPIPE) */
  1504. X
  1505. X#include <sys/time.h>
  1506. X#include "cm.h"
  1507. X
  1508. Xcm_variable *variable;
  1509. X
  1510. Xmain()
  1511. X{
  1512. X    if (0>cm_init("constant reader SIGPIPE",0,0)) exit(-1);
  1513. X
  1514. X    if (!(variable = cm_declare("variable",CM_ROLE_READER|CM_ROLE_WAKEUP))) exit(-1);
  1515. X
  1516. X    while (1) {
  1517. X        cm_sync(CM_WAIT);
  1518. X    }
  1519. X}
  1520. END_OF_FILE
  1521. if test 388 -ne `wc -c <'src/server8a.c'`; then
  1522.     echo shar: \"'src/server8a.c'\" unpacked with wrong size!
  1523. fi
  1524. # end of 'src/server8a.c'
  1525. fi
  1526. if test -f 'src/server8b.c' -a "${1}" != "-c" ; then 
  1527.   echo shar: Will not clobber existing file \"'src/server8b.c'\"
  1528. else
  1529. echo shar: Extracting \"'src/server8b.c'\" \(366 characters\)
  1530. sed "s/^X//" >'src/server8b.c' <<'END_OF_FILE'
  1531. X/* server8b.c - receive updates from common memory but do not read() */
  1532. X/* see if cmm eventually hangs on write() */
  1533. X
  1534. X#include <sys/time.h>
  1535. X#include "cm.h"
  1536. X
  1537. Xcm_variable *variable;
  1538. X
  1539. Xmain()
  1540. X{
  1541. X    if (0>cm_init("constant reader hang",0,0)) exit(-1);
  1542. X
  1543. X    if (!(variable = cm_declare("variable",CM_ROLE_READER|CM_ROLE_WAKEUP))) exit(-1);
  1544. X
  1545. X    cm_sync(CM_NO_WAIT);
  1546. X    sigpause();
  1547. X}
  1548. END_OF_FILE
  1549. if test 366 -ne `wc -c <'src/server8b.c'`; then
  1550.     echo shar: \"'src/server8b.c'\" unpacked with wrong size!
  1551. fi
  1552. # end of 'src/server8b.c'
  1553. fi
  1554. if test -f 'src/usr_get_slot.c' -a "${1}" != "-c" ; then 
  1555.   echo shar: Will not clobber existing file \"'src/usr_get_slot.c'\"
  1556. else
  1557. echo shar: Extracting \"'src/usr_get_slot.c'\" \(1508 characters\)
  1558. sed "s/^X//" >'src/usr_get_slot.c' <<'END_OF_FILE'
  1559. X/*
  1560. X
  1561. Xthese functions are used by the user to read and process information from
  1562. Xincoming slots 
  1563. X
  1564. X*/
  1565. X
  1566. X#include <stdio.h>
  1567. X#include <sys/time.h>
  1568. X#include "cm_constants.h"
  1569. X#include "cm_sd.h"
  1570. X#include "cm_interface.h"
  1571. X#include "cm_slot.h"
  1572. X
  1573. Xcm_variable *get_variable();
  1574. X
  1575. Xuser_decode_slot(s)
  1576. Xstruct slot *s;
  1577. X{
  1578. X    int rc = 0;
  1579. X
  1580. X    switch (s->s_type) {
  1581. X    case CM_SLOT_READ_RESPONSE:
  1582. X        rc = get_slot_read_response(s->s_name,
  1583. X                &s->subslot.read_response);
  1584. X        break;
  1585. X    case CM_SLOT_ERROR:
  1586. X        rc = get_slot_error(s->s_name,&s->subslot.error);
  1587. X        break;
  1588. X    default:
  1589. X        fprintf(stderr,"user_decode_slot: unknown slot type (%d)...msg aborted\n",s->s_type);
  1590. X        rc = E_CM_GET_SLOT_UNKNOWN_SLOT_TYPE;
  1591. X        break;
  1592. X    }
  1593. X    return(rc);
  1594. X}
  1595. X
  1596. X/* returns 0 if ok, negative if problem decoding slot */
  1597. Xint
  1598. Xget_slot_error(name,s)
  1599. Xchar *name;
  1600. Xstruct slot_error *s;
  1601. X{
  1602. X    fprintf(stderr,"CMM: error processing variable <%s> - %s\n",name,
  1603. X        s->msg);
  1604. X    /* isn't there a "type" field in the error subslot, too? */
  1605. X    return(0);
  1606. X}
  1607. X
  1608. X/* 0 if ok, negative if problem decoding slot */
  1609. Xint
  1610. Xget_slot_read_response(name,s)
  1611. Xchar *name;
  1612. Xstruct slot_read_response *s;
  1613. X{
  1614. X    int rc;
  1615. X    cm_variable *v;
  1616. X
  1617. X    if (!(v = get_variable(name))) {
  1618. X        fprintf(stderr,"get_slot_read_response: <%s> unknown (sent from cm)\n",v->name);
  1619. X        return(E_CM_GET_SLOT_GET_VARIABLE);
  1620. X    }
  1621. X
  1622. X    if (0 > cm_flat_to_sd(&s->fdata,&v->data))
  1623. X        return(E_CM_GET_SLOT_FLAT_TO_SD);
  1624. X    v->count = s->srr_count;
  1625. X    v->command_association = s->srr_command_association;
  1626. X    cm_time_copy(&s->srr_timestamp,&v->timestamp);
  1627. X    return(0);
  1628. X}
  1629. X    
  1630. END_OF_FILE
  1631. if test 1508 -ne `wc -c <'src/usr_get_slot.c'`; then
  1632.     echo shar: \"'src/usr_get_slot.c'\" unpacked with wrong size!
  1633. fi
  1634. # end of 'src/usr_get_slot.c'
  1635. fi
  1636. if test -f 'src/usr_put_slot.c' -a "${1}" != "-c" ; then 
  1637.   echo shar: Will not clobber existing file \"'src/usr_put_slot.c'\"
  1638. else
  1639. echo shar: Extracting \"'src/usr_put_slot.c'\" \(2058 characters\)
  1640. sed "s/^X//" >'src/usr_put_slot.c' <<'END_OF_FILE'
  1641. X
  1642. X/*
  1643. X
  1644. XThese routines build slots for the user.  These slots are placed into a
  1645. Xmsg structure and sent to the cmm.  The all return 0 for failure, or a
  1646. Xpositive number indicating the number of bytes in the slot.
  1647. X
  1648. X*/
  1649. X
  1650. X#include <stdio.h>
  1651. X#include <sys/time.h>
  1652. X#include "cm_constants.h"
  1653. X#include "cm_sd.h"
  1654. X#include "cm_slot.h"
  1655. X#include "cm_msg.h"
  1656. X#include "cm_bytestuff.h"
  1657. X#include "cm_interface.h"
  1658. X
  1659. X/* this indicates that the user wants the cmm to send back the latest value */
  1660. X/* of all variables */
  1661. Xput_slot_read(m)
  1662. Xstruct msg *m;
  1663. X{
  1664. X    struct slot s;
  1665. X    unsigned int size;
  1666. X
  1667. X    init_slot(&s,"read all",CM_SLOT_READ);
  1668. X    size = align(sizeof(struct slot_hdr));
  1669. X/*    size += align(sizeof(struct slot_read));*/
  1670. X    return(finish_slot(m,&s,size));
  1671. X}
  1672. X
  1673. Xint    /* returns size of data written in msg */
  1674. Xput_slot_write(m,name,data,cmd)
  1675. Xstruct msg *m;
  1676. Xchar *name;
  1677. Xcm_value *data;
  1678. Xint cmd;
  1679. X{
  1680. X    struct big_slot s;
  1681. X    unsigned int size;
  1682. X
  1683. X    init_slot((struct slot *)&s,name,CM_SLOT_WRITE);
  1684. X    size = align(sizeof(struct slot_hdr));
  1685. X    size += align(sizeof(struct slot_write_hdr));
  1686. X    s.subslot.write.sw_command_association = cmd;
  1687. X    size += cm_sd_to_flat(data,&s.subslot.write.fdata);
  1688. X    return(finish_slot(m,(struct slot *)&s,size));
  1689. X}
  1690. X
  1691. Xint
  1692. Xput_slot_declare(m,name,role,cmd_assoc)
  1693. Xstruct msg *m;
  1694. Xchar *name;
  1695. Xstruct usr_var_role *role;
  1696. Xint cmd_assoc;
  1697. X{
  1698. X    struct slot s;
  1699. X    unsigned int size;
  1700. X
  1701. X    init_slot(&s,name,CM_SLOT_DECLARE);
  1702. X    size = align(sizeof(struct slot_hdr));
  1703. X    size += align(sizeof(struct slot_declare));
  1704. X    /* could do some checking on the following */
  1705. X    s.subslot.declare.role.reader = role->reader;
  1706. X    s.subslot.declare.role.wakeup = role->wakeup;
  1707. X    s.subslot.declare.role.xwriter = role->xwriter;
  1708. X    s.subslot.declare.role.nonxwriter = role->nonxwriter;
  1709. X    s.subslot.declare.command_association = cmd_assoc;
  1710. X    return(finish_slot(m,&s,size));
  1711. X}
  1712. X
  1713. Xint
  1714. Xput_slot_undeclare(m,name)
  1715. Xstruct msg *m;
  1716. Xchar *name;
  1717. X{
  1718. X    struct slot s;
  1719. X    unsigned int size;
  1720. X
  1721. X    init_slot(&s,name,CM_SLOT_UNDECLARE);
  1722. X    size = align(sizeof(struct slot_hdr));
  1723. X/*    size += align(sizeof(struct slot_undeclare));*/
  1724. X    return(finish_slot(m,&s,size));
  1725. X}
  1726. END_OF_FILE
  1727. if test 2058 -ne `wc -c <'src/usr_put_slot.c'`; then
  1728.     echo shar: \"'src/usr_put_slot.c'\" unpacked with wrong size!
  1729. fi
  1730. # end of 'src/usr_put_slot.c'
  1731. fi
  1732. if test -f 'src/usr_var.c' -a "${1}" != "-c" ; then 
  1733.   echo shar: Will not clobber existing file \"'src/usr_var.c'\"
  1734. else
  1735. echo shar: Extracting \"'src/usr_var.c'\" \(2280 characters\)
  1736. sed "s/^X//" >'src/usr_var.c' <<'END_OF_FILE'
  1737. X/* usr_var.c - utility functions for user only! */
  1738. X
  1739. X#include <stdio.h>
  1740. X#include <sys/types.h>
  1741. X#include <sys/time.h>
  1742. X#include <strings.h>
  1743. X
  1744. X#include "cm_constants.h"
  1745. X#include "cm_sd.h"
  1746. X#include "cm_interface.h"
  1747. X
  1748. Xcm_variable cm_variables[CM_MAXUSERVARIABLES];
  1749. X
  1750. Xcm_variable *
  1751. Xget_variable(name)
  1752. Xchar *name;
  1753. X{
  1754. X        int i;
  1755. X
  1756. X    eprintf(10,"entering get_variable(%s)\n",name);
  1757. X        for (i=0;i<CM_MAXUSERVARIABLES;i++) {
  1758. X                /* create it if we come to an empty variable */
  1759. X                if (!cm_variables[i].status.inuse) {
  1760. X            eprintf(10,"get_variable: found empty variable slot\n");
  1761. X                    strcpy(cm_variables[i].name,name);
  1762. X            cm_sd_clear(&cm_variables[i].data);
  1763. X            cm_variables[i].role.reader = 0;
  1764. X            cm_variables[i].role.nonxwriter = 0;
  1765. X            cm_variables[i].role.wakeup = 0;
  1766. X            cm_variables[i].role.xwriter = 0;
  1767. X            cm_variables[i].old_count = 0;
  1768. X            cm_variables[i].count = 0;
  1769. X            cm_variables[i].command_association = 0;
  1770. X            cm_time_zero(&cm_variables[i].timestamp);
  1771. X            cm_variables[i].status.inuse = TRUE;
  1772. X            cm_variables[i].status.written = FALSE;
  1773. X            cm_variables[i].status.declared = FALSE;
  1774. X                    return(&cm_variables[i]);
  1775. X                }
  1776. X                /* found an old definition */
  1777. X                if (!(strcmp(cm_variables[i].name,name))) {
  1778. X            eprintf(10,"get_variable() found old defn\n");
  1779. X                        return(&cm_variables[i]);
  1780. X                }
  1781. X        }
  1782. X        /* no old definition and no space for a new one!!!! */
  1783. X        return(NULL);
  1784. X}
  1785. X
  1786. X/*
  1787. XThe following function allows the user to step through all the common
  1788. Xmemory values, for example, to see if any have changed.  If v is NULL,
  1789. Xthe first value is returned.  If no more cm_variables are in use, NULL is
  1790. Xreturned.
  1791. X
  1792. XThis function is also used by the common memory system itself, as it
  1793. Xhides the implementation of the user cm_variables as a large array.
  1794. XPresumably, it will be changed to have a hash index in the future
  1795. Xfor speed.
  1796. X*/
  1797. Xcm_variable *
  1798. Xnext_user_variable(v)
  1799. Xcm_variable *v;    /* if NULL, start from the beginning */
  1800. X{
  1801. X    if (v == 0) v = cm_variables;    /* reinitialize */
  1802. X    else v++;            /* next one */
  1803. X
  1804. X    for (;v<&cm_variables[CM_MAXUSERVARIABLES];v++) {
  1805. X        if (v->status.inuse) return(v);
  1806. X    }
  1807. X    return((cm_variable *)NULL);
  1808. X}
  1809. END_OF_FILE
  1810. if test 2280 -ne `wc -c <'src/usr_var.c'`; then
  1811.     echo shar: \"'src/usr_var.c'\" unpacked with wrong size!
  1812. fi
  1813. # end of 'src/usr_var.c'
  1814. fi
  1815. if test ! -d 'stream' ; then
  1816.     echo shar: Creating directory \"'stream'\"
  1817.     mkdir 'stream'
  1818. fi
  1819. if test -f 'stream/Makefile' -a "${1}" != "-c" ; then 
  1820.   echo shar: Will not clobber existing file \"'stream/Makefile'\"
  1821. else
  1822. echo shar: Extracting \"'stream/Makefile'\" \(932 characters\)
  1823. sed "s/^X//" >'stream/Makefile' <<'END_OF_FILE'
  1824. XCOMMON = stream.o sized_io.o
  1825. XOFILES = $(COMMON) reader.o writer.o
  1826. XHFILES = inet.h
  1827. XCFLAGS =
  1828. X#CFLAGS = -g -DDEBUG
  1829. XLIB = libstream.a
  1830. X
  1831. X# for testing purposes
  1832. X
  1833. Xtest: libstream.a reader writer
  1834. X
  1835. Xlibstream.a: stream.o sized_io.o
  1836. X    ar cr libstream.a  `lorder $(COMMON) | tsort` 
  1837. X    ranlib libstream.a
  1838. X
  1839. Xcleanup:
  1840. X    rm $(OFILES) libstream.a
  1841. X
  1842. Xinstall: libstream.a makedirs
  1843. X    cp $(HFILES) /usr/local/include/inet/stream
  1844. X    cp libstream.a /usr/local/lib
  1845. X    cp stream.3 /usr/local/man/manl/sized_io.l
  1846. X
  1847. Xmakedirs: /usr/local/include/inet /usr/local/include/inet/stream
  1848. X
  1849. X/usr/local/include/inet:
  1850. X    mkdir /usr/local/include/inet
  1851. X
  1852. X/usr/local/include/inet/stream:
  1853. X    mkdir /usr/local/include/inet/stream
  1854. X
  1855. Xlint:
  1856. X    lint -u stream.c _sized_io.c
  1857. X
  1858. Xlintc:
  1859. X    lint -Cstream stream.c _sized_io.c
  1860. X    su -c "mv llib-lstream.ln /usr/lib/lint" -f
  1861. X
  1862. Xreader: reader.o $(COMMON)
  1863. X    cc $(CFLAGS) -o reader reader.o $(LIB)
  1864. X
  1865. Xwriter:    writer.o $(COMMON)
  1866. X    cc $(CFLAGS) -o writer writer.o $(LIB)
  1867. END_OF_FILE
  1868. if test 932 -ne `wc -c <'stream/Makefile'`; then
  1869.     echo shar: \"'stream/Makefile'\" unpacked with wrong size!
  1870. fi
  1871. # end of 'stream/Makefile'
  1872. fi
  1873. if test -f 'stream/README' -a "${1}" != "-c" ; then 
  1874.   echo shar: Will not clobber existing file \"'stream/README'\"
  1875. else
  1876. echo shar: Extracting \"'stream/README'\" \(2493 characters\)
  1877. sed "s/^X//" >'stream/README' <<'END_OF_FILE'
  1878. XThis package provides a quick-and-easy means of providing reliable
  1879. Xand large-packet communication between processes.
  1880. X
  1881. XIt is especially nice because initport() does all the hard work of
  1882. Xinitializing TCP connections, and select_server_stream() does the
  1883. Xhard work of connecting processes to each other.
  1884. X
  1885. XTo install, type
  1886. X
  1887. X    make install
  1888. X
  1889. XTo test, type
  1890. X
  1891. X    make test
  1892. X    reader
  1893. X    writer    (in different window)
  1894. X    writer  (in yet another window)
  1895. X    writer  (in yet ...)
  1896. X    and so on.
  1897. X
  1898. X
  1899. Xreader and writer are two programs that should communicate with
  1900. Xeach other.  Type things into any of the writers and reader will
  1901. Xprint it out prefaced by the file descriptor the data came in on.
  1902. X
  1903. XBugs and problems to Don Libes
  1904. XNational Bureau of Standards
  1905. XBldg 220, Rm A-127
  1906. XGaithersburg, MD  20899
  1907. X(301) 975-3535
  1908. X
  1909. X
  1910. XSYNOPSIS
  1911. X
  1912. X#include <sys/socket.h>
  1913. X#include <netinet/in.h>
  1914. X#include <inet.h>
  1915. X
  1916. X    cc [options] [files] sized_io.o stream.o
  1917. X
  1918. XDESCRIPTION
  1919. X
  1920. XThis package implements packet or stream IO between a server process and
  1921. Xa number of client processes, using the TCP/IP (stream) facilities.
  1922. X
  1923. XA client uses the call:
  1924. X
  1925. X    s = initport(PORT_NUMBER(XXX),CLIENT,SOCK_STREAM);
  1926. X
  1927. Xs is the server's data socket and is used as a file descriptor in further
  1928. Xcommunication.  The port may be specified by name (PORT_NAME("foo")), if it
  1929. Xis registered.
  1930. X
  1931. XSimilarly, the server uses the following call:
  1932. X
  1933. X    s = initport(PORT_NUMBER(XXX),SERVER,SOCK_STREAM);
  1934. X
  1935. Xs is the server's connection socket.  To receive data or connections, the
  1936. Xserver calls select_server_stream().
  1937. X
  1938. X    client = select_server_stream(s,&fds);
  1939. X
  1940. XThis returns a file descriptor corresponding to a client, when a client has
  1941. Xsent a message to the server.  It handles initial connections as well as
  1942. Xclient deaths.  s is the server's connection socket that was returned by
  1943. Xinitport().  fds is an int used by select...() for storing a bit string
  1944. Xcorresponding to client sockets.  Initialize it to 0, and don't mess with it
  1945. Xafter that.
  1946. X
  1947. XTo use the file descriptors in a stream-oriented manner, use read() and
  1948. Xwrite().  To use the file descriptors in a packet-oriented manner, use
  1949. Xsized_read() and sized_write().  The sized...() calls read and write one
  1950. Xpacket at a time, while packet boundaries are ignored in read() and write().
  1951. X
  1952. X    cc = sized_read(fd,buffer,maxsize)
  1953. X    cc = sized_write(fd,buffer,size)
  1954. X
  1955. XThe arguments for sized_read() and sized_write() are very similar to read()
  1956. Xand write().  The only difference is that in sized_read(), maxsize is the
  1957. Xmaximum size of an acceptable packet.
  1958. END_OF_FILE
  1959. if test 2493 -ne `wc -c <'stream/README'`; then
  1960.     echo shar: \"'stream/README'\" unpacked with wrong size!
  1961. fi
  1962. # end of 'stream/README'
  1963. fi
  1964. if test -f 'stream/inet.h' -a "${1}" != "-c" ; then 
  1965.   echo shar: Will not clobber existing file \"'stream/inet.h'\"
  1966. else
  1967. echo shar: Extracting \"'stream/inet.h'\" \(417 characters\)
  1968. sed "s/^X//" >'stream/inet.h' <<'END_OF_FILE'
  1969. X#define TRUE        1
  1970. X#define FALSE        0
  1971. X
  1972. X#define PORT_TYPE_NAME        1
  1973. X#define PORT_TYPE_NUMBER    2
  1974. X
  1975. X#define PORT_NAME(name)        PORT_TYPE_NAME,name,(u_short)0
  1976. X#define PORT_NUMBER(number)    PORT_TYPE_NUMBER,0,(u_short)number
  1977. X
  1978. X/* sockettypes are SOCKET_STREAM and SOCKET_DGRAM */
  1979. X
  1980. X#define DATAGRAM_FLAGS    0        /* for recv and sendto */
  1981. X
  1982. X#define SERVER        1
  1983. X#define CLIENT        2
  1984. X#define server        (role == SERVER)
  1985. X#define client        (role == CLIENT)
  1986. END_OF_FILE
  1987. if test 417 -ne `wc -c <'stream/inet.h'`; then
  1988.     echo shar: \"'stream/inet.h'\" unpacked with wrong size!
  1989. fi
  1990. # end of 'stream/inet.h'
  1991. fi
  1992. if test -f 'stream/reader.c' -a "${1}" != "-c" ; then 
  1993.   echo shar: Will not clobber existing file \"'stream/reader.c'\"
  1994. else
  1995. echo shar: Extracting \"'stream/reader.c'\" \(729 characters\)
  1996. sed "s/^X//" >'stream/reader.c' <<'END_OF_FILE'
  1997. X#include <stdio.h>
  1998. X#include <sys/types.h>
  1999. X#include <sys/socket.h>
  2000. X#include <netinet/in.h>
  2001. X#include <netdb.h>
  2002. X#include "inet.h"
  2003. X
  2004. Xchar buf[2000];
  2005. X
  2006. Xmain(argc,argv)
  2007. Xint argc;
  2008. Xchar **argv;
  2009. X{
  2010. X    int writer;
  2011. X    int cc;
  2012. X    int fd;
  2013. X    int fds = 0;
  2014. X
  2015. X    /* if an arg is provided, use that as the hostname to look for the */
  2016. X    /* service */
  2017. X    fd = initport(PORT_NUMBER(2000),SERVER,SOCK_STREAM,(char *)0);
  2018. X    if (fd < 0) {
  2019. X        fprintf(stderr,"initport() = %d\n",fd);
  2020. X        exit(-1);
  2021. X    }
  2022. X
  2023. X        while (TRUE) {
  2024. X        writer = select_server_stream(fd,&fds);
  2025. X        cc = sized_read(writer,buf,2000);
  2026. X        if (cc <= 0) {
  2027. X            printf("%d: EOF\n",writer);
  2028. X            close(writer);
  2029. X            continue;
  2030. X        }
  2031. X        printf("%d: %s\n",writer,buf);
  2032. X        if (cc == 1) cc = sized_write(writer,"1 char",6);
  2033. X    }
  2034. X}
  2035. END_OF_FILE
  2036. if test 729 -ne `wc -c <'stream/reader.c'`; then
  2037.     echo shar: \"'stream/reader.c'\" unpacked with wrong size!
  2038. fi
  2039. # end of 'stream/reader.c'
  2040. fi
  2041. if test -f 'stream/stream.3' -a "${1}" != "-c" ; then 
  2042.   echo shar: Will not clobber existing file \"'stream/stream.3'\"
  2043. else
  2044. echo shar: Extracting \"'stream/stream.3'\" \(2306 characters\)
  2045. sed "s/^X//" >'stream/stream.3' <<'END_OF_FILE'
  2046. X.TH SIZED_IO 3NBS "11 January 1988"
  2047. X.SH NAME
  2048. Xinitport, sized_read, sized_write - send datagrams using TCP
  2049. X.SH SYNOPSIS
  2050. X.B #include <sys/socket.h>
  2051. X.br
  2052. X.B #include <netinet/in.h>
  2053. X.br
  2054. X.B #include <inet.h>
  2055. X.PP
  2056. X.B int s = initport(PORT_NUMBER(XXX),SERVER,SOCK_STREAM);
  2057. X.PP
  2058. X.B int client = select_server_stream(s,&fds);
  2059. X.br
  2060. X.B int s;
  2061. X.br
  2062. X.B int fds;
  2063. X.PP
  2064. X.B int cc = sized_read(fd,buffer,maxsize)
  2065. X.br
  2066. X.B int cc = sized_write(fd,buffer,size)
  2067. X.br
  2068. X.B int fd;
  2069. X.br
  2070. X.B char *buffer;
  2071. X.br
  2072. X.B int maxsize;
  2073. X.SH DESCRIPTION
  2074. XThis package implements packet or stream IO between a server
  2075. Xprocess and a number of client processes, using the TCP/IP (stream)
  2076. Xfacilities.  It is particularly useful to send packets larger than
  2077. Xthat allowed by UDP.  UDP packets are also not reliable - these are.
  2078. X.PP
  2079. XA client uses the call:
  2080. X.PP
  2081. X.B    s = initport(PORT_NUMBER(XXX),CLIENT,SOCK_STREAM);
  2082. X.PP
  2083. Xs is the server's data socket and is used as a file descriptor in further
  2084. Xcommunication.  The port may be specified by name (PORT_NAME("foo")), if it
  2085. Xis registered.
  2086. X.PP
  2087. XSimilarly, the server uses the following call:
  2088. X.PP
  2089. X.B    s = initport(PORT_NUMBER(XXX),SERVER,SOCK_STREAM);
  2090. X.PP
  2091. Xs is the server's connection socket.  To receive data or connections, the
  2092. Xserver calls select_server_stream().
  2093. X.PP
  2094. X.B    client = select_server_stream(s,&fds);
  2095. X.PP
  2096. XThis returns a file descriptor corresponding to a client, when a client has
  2097. Xsent a message to the server.  It handles initial connections as well as
  2098. Xclient deaths.  s is the server's connection socket that was returned by
  2099. Xinitport().  fds is an int used by select...() for storing a bit string
  2100. Xcorresponding to client sockets.  Initialize it to 0, and don't mess with it
  2101. Xafter that.
  2102. X.PP
  2103. XTo use the file descriptors in a stream-oriented manner, use read() and
  2104. Xwrite().  To use the file descriptors in a packet-oriented manner, use
  2105. Xsized_read() and sized_write().  The sized...() calls read and write one
  2106. Xpacket at a time, while packet boundaries are ignored in read() and write().
  2107. X.PP
  2108. X.B    cc = sized_read(fd,buffer,maxsize)
  2109. X.PP
  2110. X.B    cc = sized_write(fd,buffer,size)
  2111. X.PP
  2112. XThe arguments for sized_read() and sized_write() are very similar to read()
  2113. Xand write().  The only difference is that in sized_read(), maxsize is the
  2114. Xmaximum size of an acceptable packet.
  2115. X.SH AUTHOR
  2116. XDon Libes - National Bureau of Standards
  2117. END_OF_FILE
  2118. if test 2306 -ne `wc -c <'stream/stream.3'`; then
  2119.     echo shar: \"'stream/stream.3'\" unpacked with wrong size!
  2120. fi
  2121. # end of 'stream/stream.3'
  2122. fi
  2123. if test -f 'stream/writer.c' -a "${1}" != "-c" ; then 
  2124.   echo shar: Will not clobber existing file \"'stream/writer.c'\"
  2125. else
  2126. echo shar: Extracting \"'stream/writer.c'\" \(763 characters\)
  2127. sed "s/^X//" >'stream/writer.c' <<'END_OF_FILE'
  2128. X#include <stdio.h>
  2129. X#include <sys/types.h>
  2130. X#include <sys/time.h>
  2131. X#include <sys/socket.h>
  2132. X#include <netinet/in.h>
  2133. X/* #include <netdb.h> */
  2134. X#include "inet.h"
  2135. X
  2136. Xchar msg[2000];
  2137. X
  2138. Xstruct timeval timeout = {0L, 0L};
  2139. Xint maxfds;
  2140. X
  2141. Xmain(argc,argv)
  2142. Xint argc;
  2143. Xchar **argv;
  2144. X{
  2145. X    int cc;
  2146. X    int i;
  2147. X    int fd;
  2148. X    int readfds;
  2149. X
  2150. X    maxfds = getdtablesize();
  2151. X    fd = initport(PORT_NUMBER(2000),CLIENT,SOCK_STREAM,argc>1?argv[1]:"");
  2152. X
  2153. X    if (fd < 0) {
  2154. X        fprintf(stderr,"initport() = %d\n",fd);
  2155. X        exit(-1);
  2156. X    }
  2157. X    for (i=0;;i++) {
  2158. X        printf("%d: ",i);
  2159. X        gets(msg);
  2160. X        cc = sized_write(fd,msg,strlen(msg)+1);
  2161. X        readfds = 1<<fd;
  2162. X        if (0 < select(maxfds,&readfds,0,0,&timeout)
  2163. X           && readfds == 1<<fd) {
  2164. X            cc = sized_read(fd,msg,2000);
  2165. X            msg[cc] = '\0';
  2166. X            printf("msg from server: %s\n",msg);
  2167. X        }
  2168. X    }
  2169. X}
  2170. END_OF_FILE
  2171. if test 763 -ne `wc -c <'stream/writer.c'`; then
  2172.     echo shar: \"'stream/writer.c'\" unpacked with wrong size!
  2173. fi
  2174. # end of 'stream/writer.c'
  2175. fi
  2176. echo shar: End of archive 1 \(of 4\).
  2177. cp /dev/null ark1isdone
  2178. MISSING=""
  2179. for I in 1 2 3 4 ; do
  2180.     if test ! -f ark${I}isdone ; then
  2181.     MISSING="${MISSING} ${I}"
  2182.     fi
  2183. done
  2184. if test "${MISSING}" = "" ; then
  2185.     echo You have unpacked all 4 archives.
  2186.     rm -f ark[1-9]isdone
  2187. else
  2188.     echo You still need to unpack the following archives:
  2189.     echo "        " ${MISSING}
  2190. fi
  2191. ##  End of shell archive.
  2192. exit 0
  2193.  
  2194.